var sWebRoot = $('base').attr('href');
if (!sWebRoot) {
	sWebRoot = "";
}
function SubmitForm(form, clazz) {
	if (null == form || undefined == form) {
		form = "dwForm";
	}
	return $.trim($.ajax({
		url : 'runJavaMethod.json',
		data : "isHttpPerform=1&class=" + clazz + "&"
				+ $("#" + form).serialize() + "&" + getRandom(),
		async : false,
		type : 'POST',
		cache : false
	}).responseText);
}

/**
 * 运行远程Java方法
 */
function RunJavaMethod(clazz, method, param) {
	if (typeof param == 'string') {
		alert('参数类型错误!');
		return;
	}
	param = param || {};
	param['class'] = clazz;
	param['method'] = method;
	param['r'] = getRandom();

	var json = $.ajax({
		url : 'runJavaMethod.json',
		data : param,
		async : false,
		dataType : 'json',
		type : 'post',
		contentType : 'application/x-www-form-urlencoded;charset=UTF-8'
	}).responseJSON;
	if (json && !json['success']) {
		alert(json['msg']);
	} else {
		return json['data'];
	}
}

/**
 * 运行远程Java方法,带事务
 */
function RunJavaMethodTrans(clazz, method, param) {
	if (typeof param == 'string') {
		alert('参数类型错误!');
		return;
	}
	param = param || {};
	param['class'] = clazz;
	param['method'] = method;
	param['isTrans'] = 1;
	param['r'] = getRandom();
	var json = $.ajax({
		url : 'runJavaMethod.json',
		data : param,
		async : false,
		dataType : 'json',
		type : 'post',
		contentType : 'application/x-www-form-urlencoded;charset=UTF-8'
	}).responseJSON;
	if (json && !json['success']) {
		alert(json['msg']);
	} else {
		return json['data'];
	}
}

/**
 * 执行指令服务
 */
function callCmd(cmd, param) {
	return $.ajax({
		url : sWebRoot + '/server?' + cmd + '=' + param + '&r=' + getRandom(),
		async : false
	}).responseText.trim();
}

function getRandom() {
	return new Date().getTime();
}

// 翻转替换里面所有的html代码的尖括弧
function replaceRevertAllHTML(txt) {
	var value = txt;
	var leftCarr = /&lt;/g;
	var rightCarr = /&gt;/g;
	var dan = /&#39;/g;
	var and = /&amp;/g;
	var shuang = /&quot;/g;
	value = value.replace(leftCarr, "<");
	value = value.replace(rightCarr, ">");
	value = value.replace(shuang, "\"");
	value = value.replace(dan, "\'");
	value = value.replace(and, "&");
	return value;
}

function showImagePanel(img) {
	var imgPath = $(img).parent().children(':hidden').val();
	var doNo = $(img).parentsUntil('.dwForm').find("input[name=doNo]").val();
	DWControl.Window({
		id : 'test',
		title : '图片上传',
		href : 'comm/imageTagPanel.jsp',
		param : 'doNo=' + doNo + '&path=' + imgPath,
		width : 600,
		height : 400
	}, function() {
		if (document.test_iframe.img) {
			$(img).parent().children(':hidden').val(
					document.test_iframe.img.getAttribute("src"));
			$(img).attr('src', document.test_iframe.img.getAttribute("src"));
		}
	});
}